package com.tenement.controller;

import com.tenement.common.Axios;
import com.tenement.entity.Role;
import com.tenement.enums.RespBusiness;
import com.tenement.service.RoleService;
import com.tenement.vo.QueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 *  控制层。
 *
 * @author BertXie
 * @since 1.0.1
 */
@RestController
@RequestMapping("/role")
@RequiredArgsConstructor
@Api(tags = "角色管理")
public class RoleController {

    private final RoleService roleService;


    @ApiOperation("操作数据")
    @PutMapping("operator")
    public Axios operator(@RequestBody Role role) {
        return roleService.saveOrUpdate(role) ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }


    @ApiOperation("获取角色集合")
    @PostMapping("list")
    public Axios list(@RequestBody QueryVo queryVo) {
        return Axios.success(roleService.list(queryVo));
    }

    @ApiOperation("根据Id获取角色")
    @GetMapping("oneId/{id}")
    public Axios oneId(@PathVariable Serializable id) {
        return Axios.success(roleService.getById(id));
    }

    @ApiOperation("删除数据")
    @DeleteMapping("remove")
    public Axios remove(@RequestBody List<Long> ids) {
       return roleService.remove(ids) > 0 ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }
}
